<?php 

session_start();
 
if(!isset($_SESSION['username'])){
	if($_POST){
		$username = !empty($_POST['username']) ? $_POST['username'] : false ;
		$password = !empty($_POST['password']) ? $_POST['password'] : false ;

		if(!$username){
			$error =  "请输入用户名";
		}

		$userData = include './user.php';
		foreach ($userData as $value) {
			// var_dump($value,$username);
			// exit();
			if(in_array($username, $value)){
				$user = $value; 
			}
		}

		if(!isset($user)){
			$error =  "用户名或者密码不正确";
		}else{
			if($user['password']!=md5($password)){
				$error =  "用户名或者密码不正确";
			}

		}
		if(!isset($error)){
			
			$_SESSION['username']=$user['username'];
			$message = "登录成功";
			include './tpl/success.html';
			exit;
		}

	}

	include './tpl/login.html';


}else{
	$message = "你已经登录";
	include './tpl/success.html';
}


 ?>